package muslim30;

import java.util.Calendar;
import java.util.GregorianCalendar;


public class DateChecker {
	
	public static final int RAMADAN = 0;
	public static final int RAMADAN_FINISHED = 1;
	public static final int NEW_YEAR = 2;
	public static final int WAIT_RAMADAN = 3;
	
	public static final int DAY_IN_MILLIS = 24*60*60*1000;
	
	private Calendar d = null;
	private Calendar ramadanStart = null;
	private int diff;
	
	public DateChecker() {
		setDate(Calendar.getInstance());
	}
	
	public int getDiff() {
		return (int) ((d.getTimeInMillis() - ramadanStart.getTimeInMillis())/(float)DAY_IN_MILLIS);
	}
	
	public int checkRamadan() {
		//Log.i("DIFF", ""+diff);
		
		if(diff < -30)
			return NEW_YEAR;
		else if(diff < 0)
			return WAIT_RAMADAN;
		else if(diff < 30)
			return RAMADAN;
		else
			return RAMADAN_FINISHED;
	}
	
	private void getRamadanStart(int year) {	
		switch(year) {
		case 2012:
			ramadanStart = new GregorianCalendar(2012, 7-1, 20);
			break;
		case 2013:
			ramadanStart = new GregorianCalendar(2013, 7-1, 9);
			break;
		default:
			ramadanStart = null;
		}
	}
	
	public void setDate(Calendar date) {
		this.d = date;
		getRamadanStart(d.get(Calendar.YEAR));	
		diff = getDiff();
	}
}
